import {Injectable} from '@angular/core';
import {BaseHttpService} from '../base-http.service';
import {Observable} from 'rxjs';
import {PageInfo, SearchCommonVO} from '../../types';

export interface QuestionBankListModel {
  id: number;
  name: string;
  remark: string;
  radio: Date;
  judge: string;
  createTime: Date;
}

export interface QuestionBankModel {
  id: number;
  name: string;
  remark?: string;
}

@Injectable({
  providedIn: 'root'
})


export class QuestionBankService {

  constructor(public http: BaseHttpService) {
  }

  /*获取题库列表数据*/
  public getQuestionBankList(param: SearchCommonVO<any>): Observable<PageInfo<QuestionBankListModel>> {
    return this.http.post('/question-bank', param);
  }

  /*新增题库名称*/
  public addQuestionBank(param: QuestionBankModel): Observable<QuestionBankModel> {
    return this.http.post('/insert-question-bank', param, {needSuccessInfo: true});
  }

  /*编辑题库信息*/
  public editQuestionBank(param: QuestionBankModel): Observable<any> {
    return this.http.put('/question-bank', param, {needSuccessInfo: true});
  }


  /*题库详情*/
  public getQuestionBankDetail(id: number): Observable<QuestionBankModel> {
    return this.http.get(`/question-bank/${id}`);
  }

  /*删除题库*/
  public delQuestionBank(idArray: number[]): Observable<void> {
    return this.http.post('/question-bank/', {ids: idArray}, {needSuccessInfo: true});
  }
}
